package com.resume.aipeople.repository;

import com.resume.aipeople.entity.ChatSession;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface ChatSessionRepository extends JpaRepository<ChatSession, Long> {
    
    Optional<ChatSession> findBySessionId(String sessionId);
    
    List<ChatSession> findByUserAndIsActiveTrueOrderByUpdatedAtDesc(com.resume.aipeople.entity.User user);
    
    List<ChatSession> findByAnonymousUserIdAndIsActiveTrueOrderByUpdatedAtDesc(String anonymousUserId);
    
    List<ChatSession> findByCharacterIdAndIsActiveTrueOrderByUpdatedAtDesc(Long characterId);
    
    // 查找用户与特定角色的最新活跃会话
    Optional<ChatSession> findFirstByUserAndCharacterAndIsActiveTrueOrderByUpdatedAtDesc(
        com.resume.aipeople.entity.User user, 
        com.resume.aipeople.entity.Character character
    );
    
    // 查找用户与特定角色的所有活跃会话
    List<ChatSession> findByUserAndCharacterAndIsActiveTrueOrderByUpdatedAtDesc(
        com.resume.aipeople.entity.User user, 
        com.resume.aipeople.entity.Character character
    );
    
    void deleteBySessionId(String sessionId);
} 